package com.wenhuitec.android.tang.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dhkj.web.bean.Zweekmenubak;
import com.wenhuitec.android.tang.R;
import com.wenhuitec.android.tang.sysui.model.PickModel;

import java.util.List;

public class FoodsGvAdapter extends BaseAdapter {
    private Context mContext;

    private List<Zweekmenubak> list;

    private GvOnClick mGvOnClick;

    public FoodsGvAdapter(Context context, List<Zweekmenubak> list) {
        this.mContext = context;
        this.list = list;
    }

    public void setmGvOnClick(GvOnClick mGvOnClick) {
        this.mGvOnClick = mGvOnClick;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final KeyAdapter.ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_foodname, null);
            holder = new KeyAdapter.ViewHolder();
            holder.btnNumber = (TextView) convertView.findViewById(R.id.btNumber);
            convertView.setTag(holder);
        } else {
            holder = (KeyAdapter.ViewHolder) convertView.getTag();
        }
        holder.btnNumber.setText(list.get(position).getName().trim());
        holder.btnNumber.setOnClickListener(v -> {
            if (mGvOnClick != null) {
                mGvOnClick.userClick(list.get(position));
            }
        });
//        if (position % 2 == 0) {
////            holder.btnNumber.setBackgroundColor(Color.parseColor("#cccccc"));
//        } else {
////            holder.btnNumber.setBackgroundColor(Color.parseColor("#f2f2f2"));
//        }
        holder.btnNumber.setBackgroundColor(Color.parseColor("#f2f2f2"));
        return convertView;
    }

    static class ViewHolder {
        public TextView btnNumber;
    }

    public interface GvOnClick {
        void userClick(Zweekmenubak zweekmenubak);
    }
}
